package com.ff.javamonkey.sqlite;

import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ACRLDbAdapter {

	public static final String KEY_ROWID = "id_";
	public static final String KEY_TYPE = "type_";
	public static final String KEY_DATAFILEID = "datafileid_";
	public static final String KEY_FILENAME = "filename_";
	public static final String KEY_DATATYPE = "datatype_";
	public static final String KEY_TARGETPATH = "targetpath_";
	public static final String KEY_TARGETCSCI = "targetcsci_";
	public static final String KEY_EFFECTIVETIME = "effectivetime_";
	public static final String KEY_AIRCRAFT = "aircraft_";
	public static final String KEY_FILESTATUS = "filestatus_";
	public static final String KEY_FILEHASH = "filehash_";
	public static final String TABLE = "acrlac_";
	
	private static final String [] allRows =
		new String[] {KEY_ROWID, KEY_TYPE, KEY_DATAFILEID, KEY_FILENAME, KEY_DATATYPE, KEY_TARGETPATH,
			KEY_TARGETCSCI, KEY_EFFECTIVETIME, KEY_AIRCRAFT, KEY_FILESTATUS, KEY_FILEHASH};
	
	private OpenDatabaseHelper mDbHelper;
	private SQLiteDatabase mDb;
	
	public ACRLDbAdapter(OpenDatabaseHelper mDbHelper) {
		this.mDbHelper = mDbHelper;
	}
	
	public ACRLDbAdapter open() throws SQLException {
		mDb = mDbHelper.getWritableDatabase();
		return this;
	}
	
	public void close() {
		mDbHelper.close();
	}
	
	public Cursor findItem(long rowId) throws SQLException {
		return mDb.query(true, TABLE, allRows, KEY_ROWID + "=" + rowId, null, null, null, null, null);
	}

	public Cursor fetchAll() {
		return mDb.query(TABLE, allRows, null, null, null, null, KEY_ROWID);
	}
}
